# coding=utf-8
from django.db import models

class AAA(models.Model):
    username = models.CharField(max_length=30)
    realname = models.CharField(max_length=30)
    
    def __init__(self, username='Jim', realname=u'张三'):
        self.id = 0
        self.username = username
        self.realname = realname        
    
    def jsonit(self):
        import json
        j = []
        for field in self._meta.fields:
            j.append(field.name)
        d = {}
        for attr in j:
            d[attr] = getattr(self, attr)
        return json.dumps(d)
        
    class Meta:
        db_table = 'User'

a=AAA('tom', u'zhangsan')
print a.jsonit()